package com.cenntro.oss.common.startup;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.cenntro.common.thread.ThreadPool;
import com.cenntro.common.websocket.WebsocketServer;
import com.cenntro.oss.service.DevDeviceStaticService;
import com.cenntro.oss.service.SysAgentService;

/**
 * 1、@Order注解 如果有多个实现类，而你需要他们按一定顺序执行的话，可以在实现类上加上@Order注解。@Order(value=整数值)。
 * SpringBoot会按照@Order中的value值从小到大依次执行。
 * 2、如果你发现你的实现类没有按照你的需求执行，请看一下实现类上是否添加了Spring管理的注解（@Component）。
 * 
 * @author Administrator
 *
 */
@Component
@Order(value = 2)
public class StartUpRunner implements CommandLineRunner {

	private static final Logger LOG = LoggerFactory.getLogger(StartUpRunner.class);
	@Resource
	private SysAgentService sysAgentService;
	@Resource
	private DevDeviceStaticService devDeviceStaticService;
	
	@Override
	public void run(String... args) throws Exception {
		LOG.info("系统初始化 #####");
		ThreadPool.getInstance().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    new WebsocketServer(8083).run();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });;
		
//		List<SysAgentDO> list = sysAgentService.selectPage(null);
//		for (SysAgentDO agent : list){
//			LOG.info("修改agent 车辆数量");
//			DevDeviceStaticDO dsd = new DevDeviceStaticDO();
//			dsd.setAgentID(agent.getId());
//			int count = devDeviceStaticService.selectCount(dsd);
//			agent.setCarNum(count);
//			sysAgentService.update(agent);
//		}
//		
	}
	/**
	 * 初始化vincode 分区信息
	 */
	public void init(){
	
	}
	
	/**
	 * 暂时是单点
	 * 
	 */
	public void getAddressJob(){
		
	}

}
